package com.scpii.api.domain.push;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;

import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.springframework.format.annotation.DateTimeFormat;

import com.scpii.api.common.Constants;
import com.scpii.api.common.json.serializer.ResourceUrlSerializer;
import com.scpii.api.domain.content.Body;

public class Message implements Serializable {
	
	//消息状态：0表示不可以发送、 1表示可以发送、 2表示IOS已推送、  3表示已拉取、  4表示超时
	public final static class status{
		/**
		 * 0表示不可以发送
		 */
		public final static Integer  NONE_SEND = 0;
		/**
		 * 1表示可以发送(android可以通过客户端进行拉取该消息，IOS可以向APNS服务器推消息)
		 */
		public final static Integer  OK_SEND = 1;  
		/**
		 * 2表示IOS已推送 (IOS已经向APNS推送)
		 */
		public final static Integer  HAS_PUSH = 2;
		/**
		 * 3表示已拉取(android拉取后将从状态1变为3，IOS则是从2变为3的)
		 */
		public final static Integer  HAS_PULL = 3;
		
		/**
		 * 4表示用户已经阅读
		 */
		public final static Integer  HAS_READ = 4;
		/**
		 * 5表示超时
		 */
		public final static Integer  TIME_OUT = 5;
	}
	
	
    private Long messageId;

    @JsonIgnore
    private Long appId;

    private String title;

    @JsonSerialize(using = ResourceUrlSerializer.class, include = JsonSerialize.Inclusion.NON_NULL)
    private String icon;

    private String summary;

    private List<Body> body;
    
    @DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
    private Date startTime;

    @JsonIgnore
    @DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
    private Date expireTime;

    @JsonIgnore
    private Date createTime;

    private Integer messageStatus;

    private static final long serialVersionUID = 1L;

    

    public Long getMessageId() {
		return messageId;
	}

	public void setMessageId(Long messageId) {
		this.messageId = messageId;
	}

	public Long getAppId() {
        return appId;
    }

    public void setAppId(Long appId) {
        this.appId = appId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title == null ? null : title.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
    	if(icon != null){
	    	Matcher matcher = ResourceUrlSerializer.URL_REG_PATTERN.matcher(icon);
			if (!matcher.matches()) {
				icon = StringUtils.startsWith(icon, "/") ? icon : "/" + icon;
				icon = Constants.RESOURCE_ROOT_URL + icon;
			}
    	}
		
        this.icon = icon == null ? null : icon.trim();
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary == null ? null : summary.trim();
    }


    public List<Body> getBody() {
		return body;
	}

	public void setBody(List<Body> body) {
		this.body = body;
	}

	public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getMessageStatus() {
        return messageStatus;
    }

    public void setMessageStatus(Integer messageStatus) {
        this.messageStatus = messageStatus;
    }
}